import QtQuick 2.0
import QtGraphicalEffects 1.0


Item{
    id:root
    property string  source
    property int  diameter:140

    property bool isGif: false

    onSourceChanged: {
        judgeFormat(source)
    }

    width: diameter
    height: width

    Image{
        id:img
        sourceSize: Qt.size(parent.width, parent.height)
        fillMode:Image.PreserveAspectFit
        smooth: true
        visible: false
        source: root.source
    }

    AnimatedImage {
        id: animation
        source: root.source
        visible: false
    }

    Rectangle{
        id:mask
        visible: false
        smooth:true
        width: diameter
        height: width
        radius: width/2
    }

    OpacityMask{
        anchors.fill: parent
        source: isGif? animation:img
        maskSource: mask
    }


    function judgeFormat(data){
        var format = data.slice(-3,source.length)
        if(format === "gif"){
            isGif = true
        }
    }
}
